<?php
/**
 * Created by PhpStorm
 * User: whh
 * Date: 2022/7/21
 * Time: 16:09
 */

namespace app\backstage\controller;


use think\Controller;
use think\facade\Request;

class DataCenter extends Controller
{
    protected $middleware = [
        'VerifyJwt' => ['except' => []],
        'VerifyPower' => ['except' => []],
    ];

    public function index()
    {
        $UserRechargeAmountReport = \think\facade\App::model('UserRechargeAmountReport', 'logic');
        $userRechargeRank = $UserRechargeAmountReport->getListRank(['page'=>1,'limit'=>10]);

        $Console = \think\facade\App::model('Console', 'logic');
        $summary['today_total_recharge'] = $Console->getTotalRecharge(1);
        $summary['30_total_recharge'] = $Console->getTotalRecharge(2);
        $summary['total_deduction_amount'] = $Console->getTotalDeductionAmount(1);
        $summary['today_deduction_amount'] = $Console->getTotalDeductionAmount(2);
        $summary['30_total_unsettlement_amount'] = $Console->getTotalSettlementAmount(1);
        $summary['30_total_settlement_amount'] = $Console->getTotalSettlementAmount(2);

        $SettlementAmountAgent = $Console->getTotalSettlementAmountAgent();

        $summary['total_settlement_amount'] = $SettlementAmountAgent['settlement_amount'];
        $summary['total_unsettlement_amount'] = $SettlementAmountAgent['unsettlement_amount'];

        $summary['total_user_num'] = $Console->getTotalUserNum(1);
        $summary['total_user_jiazhuo'] = $Console->getTotalUserNum(2);

        $start_date = date('Y-m-d', strtotime('-29days'));
        $end_state = date('Y-m-d');
        $days = getDayByRange($start_date,$end_state);

        $UserGrowthTrendReport = \think\facade\App::model('UserGrowthTrendReport', 'logic');
        $trend_growths = $UserGrowthTrendReport->getListBy30();

        $new_user_num_growth = $trend_growths['new_user_num'];
        $jiazhuo_user_num_growth = $trend_growths['jiazhuo_user_num'];;

        $this->assign('jiazhuo_user_num_growth',json_encode($jiazhuo_user_num_growth));
        $this->assign('new_user_num_growth',json_encode($new_user_num_growth));
        $this->assign('days',json_encode($days));
        $this->assign('summary',$summary);
        $this->assign('userRechargeRank',$userRechargeRank);
        $this->assign('role_name',request()->_role->alias);

        $template = 'index';

        if(request()->_role->alias == 'agent')
        {
            $template = 'index_agent';
        }

        if(request()->_role->alias == 'channel')
        {
            $template = 'index_channel';
        }

        if(request()->_role->alias == 'eb')
        {
            $template = 'index_eb';
        }

        return $this->fetch($template);
    }
}